﻿using System.IO;
using System.Net;
using NUnit.Framework;

namespace Twitter.Tests
{
	[TestFixture]
	public class TestRequestContextFixture : TestBase
	{
		[Test]
		public void ShouldReturnMockData()
		{
			using (TestRequestContext ctx = new TestRequestContext())
			{
				ctx.AddResponse(TestRun.GetUri("foo.xml"), "foo");
				ctx.AddResponse(TestRun.GetUri("bar.xml"),
					output => output.Write("bar"));
				ctx.AddResponse(TestRun.GetUri("baz.xml"),
					output => output.Write("baz"));

				WebRequest request = WebRequest.Create(TestRun.GetUri("foo.xml"));
				using (Stream stream = request.GetResponse().GetResponseStream())
				using (StreamReader reader = new StreamReader(stream))
				{
					Assert.AreEqual("foo", reader.ReadToEnd());
				}

				request = WebRequest.Create(TestRun.GetUri("bar.xml"));
				using (Stream stream = request.GetResponse().GetResponseStream())
				using (StreamReader reader = new StreamReader(stream))
				{
					Assert.AreEqual("bar", reader.ReadToEnd());
				}

				request = WebRequest.Create(TestRun.GetUri("baz.xml"));
				using (Stream stream = request.GetResponse().GetResponseStream())
				using (StreamReader reader = new StreamReader(stream))
				{
					Assert.AreEqual("baz", reader.ReadToEnd());
				}
			}
		}
	}
}
